package com.cn.controller;

import com.cn.domain.Video;
import com.cn.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 伍崇武
 * @date 2021-08-24 0024 - 下午 2:06
 */
@RestController
@RequestMapping("api/v1/video")
public class VideoController {

    @Autowired
    private VideoService service;

    @RequestMapping("/find_by_id")
    public Object findById(Integer videoId , HttpServletRequest request){
        Video video = service.findById(videoId);
        // 查看负载均衡调用的是哪个节点机器
        video.setServerInfo(request.getServerName()+":"+request.getServerPort());
        return video;
    }

    @PostMapping("/postTest")
    public Object postTest(@RequestBody Video video){
        System.out.println(video.getTitle());
        System.out.println(video.getSummary());
        return video;
    }
}
